//package cn.steel.config;
//
//import cn.steel.domain.entity.User;
//import cn.steel.mapper.UserMapper;
//import lombok.RequiredArgsConstructor;
//import org.springframework.boot.CommandLineRunner;
//import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
//import org.springframework.stereotype.Component;
//
//import java.util.List;
//
//@Component
//@RequiredArgsConstructor
//public class PasswordEncoderRunner implements CommandLineRunner {
//
//    private final UserMapper userMapper;
//    private final BCryptPasswordEncoder passwordEncoder;
//
//    @Override
//    public void run(String... args) throws Exception {
//        // 获取所有用户
//        List<User> users = userMapper.findUsersPaginated(null, null, null);
//        for (User user : users) {
//            // 检查密码是否已经是 BCrypt 加密格式（以 $2a$ 开头）
//            if (!user.getPassword().startsWith("$2a$")) {
//                String encryptedPassword = passwordEncoder.encode(user.getPassword());
//                user.setPassword(encryptedPassword);
//                userMapper.updateUser(user);
//                System.out.println("Updated password for user: " + user.getUsername());
//            }
//        }
//        System.out.println("Password encryption completed.");
//    }
//}